<?php
// 前台学校安全信息管理模块
class AqyjAction extends CommonAction {
	function _filter(&$map){
		if('POST'==$_SERVER['REQUEST_METHOD']||$_SESSION['searchYJ']>0){
			//if($_POST['status2']){$map['status2'] = array('eq',$_POST['status2']);}
			$map['status2'] = $_POST['status2']?array('eq',$_POST['status2']):array('eq',$_SESSION['searchYJ']);
			$_SESSION['searchYJ'] = $_POST['status2'];
		}else{
			$map['status2'] = array('eq',0);
			$_SESSION['searchYJ'] = 0;
		}
		if(0!=$_SESSION['dwid'])$map['dwid'] = array('eq',$_SESSION['dwid']);
		$map['title|dwmc'] = array('like',"%".$_POST['keyword']."%");
	}
		
	function showSchoolList(){
		$model = new Model();
		$list = $model->query("select id,sName,sType from think_school order by sName");
		echo json_encode($list);
	}
	
	function updateYj() {
        //B('FilterString');
        $model = D('Aqyj');
        $data['remarks2'] 	= $_POST['remarks2'];
		$data['status2']	= 1;
        // 更新数据
        $list = $model->where('id='.$_POST['id'])->save($data);
        if (false !== $list) {
            //成功提示
            $this->assign('jumpUrl', Cookie::get('_currentUrl_'));
            $this->success('编辑成功!',true);
        } else {
            //错误提示
           $this->error('编辑失败!',true);
        }
    }
	
	//重写list,主要是为了排序
	protected function _list($model, $map, $sortBy = '', $asc = false) {
        //排序字段 默认为主键名
        if (isset($_REQUEST ['_order'])) {
            $order = $_REQUEST ['_order'];
        } else {
            $order = !empty($sortBy) ? $sortBy : 'alertDate';
        }
        //排序方式默认按照倒序排列
        //接受 sost参数 0 表示倒序 非0都 表示正序
        if (isset($_REQUEST ['_sort'])) {
            $sort = $_REQUEST ['_sort'] ? 'asc' : 'desc';
        } else {
            $sort = $desc ? 'desc' : 'asc';
        }
        //取得满足条件的记录数
        $count = $model->where($map)->count('id');
        if ($count > 0) {
            import("ORG.Util.Page");
            //创建分页对象
            if (!empty($_REQUEST ['listRows'])) {
                $listRows = $_REQUEST ['listRows'];
            } else {
                $listRows = '';
            }
            $p = new Page($count, $listRows);
            //分页查询数据

            $voList = $model->where($map)->order("`" . $order . "` " . $sort)->limit($p->firstRow . ',' . $p->listRows)->select();
            //echo $model->getlastsql();
            //分页跳转的时候保证查询条件
            foreach ($map as $key => $val) {
                if (!is_array($val)) {
                    $p->parameter .= "$key=" . urlencode($val) . "&";
                }
            }
            //分页显示
            $page = $p->show();
            //列表排序显示
            $sortImg = $sort; //排序图标
            $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列'; //排序提示
            $sort = $sort == 'desc' ? 1 : 0; //排序方式
            //模板赋值显示
            $this->assign('list', $voList);
            $this->assign('sort', $sort);
            $this->assign('order', $order);
            $this->assign('sortImg', $sortImg);
            $this->assign('sortType', $sortAlt);
            $this->assign("page", $page);
        }
        Cookie::set('_currentUrl_', __SELF__);
        return;
    }
}
?>